﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;



namespace deFramework.Common
{
    /// <summary>
    /// 
    /// </summary>
    public class FrameworkLogging
    {


        #region "Constructors, Variables, SetCodeName" 
	
        /// <summary>
        /// 
        /// </summary>
        public FrameworkLogging() 
		{
		
		}

        /// <summary>
        /// 
        /// </summary>
        /// <param name="aAssemblyName"></param>
        /// <param name="aProjectName"></param>
        public FrameworkLogging(string aAssemblyName, string aProjectName) 
		{
			this.mAssemblyName = aAssemblyName; 
			this.mProjectName = aProjectName; 										
		}
		
        /// <summary>
        /// 
        /// </summary>
        /// <param name="aAssemblyName"></param>
        /// <param name="aProjectName"></param>
		public void SetCodeName(string aAssemblyName, string aProjectName) 
		{
			this.mAssemblyName = aAssemblyName; 
			this.mProjectName = aProjectName; 										
		}
		
		
		private string mAssemblyName = "unspecified"; 
		private string mProjectName = "unspecified"; 
        //private string kTAG = "XXXX"; 
		
		
	#endregion 

    /// <summary>
    /// 
    /// </summary>
    /// <param name="ex"></param>
    /// <param name="aMethodName"></param>
    /// <returns></returns>
	public bool BasicException(Exception ex, string aMethodName) 
	{
		return this.StandardLog(aMethodName, "information", ex.Message); 
	}
	

	
	/// <summary>
	/// 
	/// </summary>
	/// <param name="aMethodName"></param>
	/// <param name="aSeverity"></param>
	/// <param name="aMessage"></param>
	/// <returns></returns>
	/// <example>
	/// this.mLog.StandardLog("Page_Load", "information", "Hello World"); 
	/// </example>
	public bool StandardLog(string aMethodName, string aSeverity, string aMessage) 
	{
		    bool l_Result = false; 
		    try 
		    {
			//TraceProvider.RegisterTraceProvider();
                //Microsoft.SharePoint.
                //    TraceProvider.WriteTrace(TraceProvider.TagFromString(this.kTAG), TraceProvider.StringToSeverity(aSeverity), 
                //Guid.NewGuid(), aMethodName, this.mAssemblyName, this.mProjectName, aMessage);
			//TraceProvider.UnregisterTraceProvider(); 
			l_Result = true; 
			}
			catch { } 
			return l_Result; 
	
	}
	
	
		/// <summary>
		/// Makes a simple log entry into the ULS 
		/// </summary>
		/// <param name="aLogText"></param>
		/// <returns>TRUE if successful in making log entry without an exception; FALSE if an untrapped exception occurs.</returns>
		[Obsolete("Please use StandardLog(MethodName, \"information\", Message).")]
		 public bool SimpleLog(string aLogText) 
		 {
		    bool l_Result = false; 
		    try 
		    {
			//TraceProvider.RegisterTraceProvider();
            //TraceProvider.WriteTrace(TraceProvider.TagFromString("ALEX"), TraceProvider.StringToSeverity("Information"), 
            //    Guid.NewGuid(), "Unknown(SimpleLog)", "unspecified", "unspecified", aLogText);
			//TraceProvider.UnregisterTraceProvider(); 
			l_Result = true; 
			}
			catch { } 
			return l_Result; 
		 }
		 
		 
		 
//         TraceProvider.RegisterTraceProvider();
//TraceProvider.WriteTrace(TraceProvider.TagFromString("XXXX (must be 4 letter tag)"), TraceProvider.StringToSeverity("Exception or Information"), 
//Guid.NewGuid(), "Method Name", "Assembly Name", "Project Name", "Message");
//TraceProvider.UnregisterTraceProvider(); 
	
	
	
	
	
	//Microsoft.Office.Server.Diagnostics.PortalLog.LogString(”Exception Occurred: {0} || {1}”, Ex.Message, Ex.StackTrace);
	
	
	
	}
	
}
